using System;
using System.Collections.Generic;
using System.Xml;
using System.Collections.ObjectModel;

namespace planning
{
	public class Horaire : Ressource
	{
		// ----- ATTRIBUTS -----
		private DateTime debut;
		private DateTime fin;

		// ----- CONSTRUCTEURS -----
		public Horaire()
		{
			// Start of user code for default constructor
			// End of user code for default constructor
		}

		// ----- ACCESSEURS -----
		public DateTime Debut
		{
			get { return debut; }
			set { debut = value; ObjectChanged("debut"); }
		}

		public DateTime Fin
		{
			get { return fin; }
			set { fin = value; ObjectChanged("fin"); }
		}


		private static Dictionary<string, Horaire> references = new Dictionary<string, Horaire>();

		public static new Horaire fromXml(XmlNode node)
		{
			Horaire horaire;
			XmlNode refAttribute = node.SelectSingleNode("@ref");
			XmlNode idAttribute = node.SelectSingleNode("@id");

			if(refAttribute != null) {
				if(references.ContainsKey(refAttribute.Value)) {
					return references[refAttribute.Value];
				} else {
					horaire = new Horaire();
					references.Add(refAttribute.Value, horaire);
					return horaire;
				}
			}

			if(idAttribute != null && references.ContainsKey(idAttribute.Value)) {
				horaire = references[idAttribute.Value];
			} else {
				horaire = new Horaire();

				if(idAttribute != null) {
					references.Add(idAttribute.Value, horaire);
				}
			}

			if(node.SelectSingleNode("@debut") != null)
				horaire.Debut = Convert.ToDateTime(node.SelectSingleNode("@debut").Value);

			if(node.SelectSingleNode("@fin") != null)
				horaire.Fin = Convert.ToDateTime(node.SelectSingleNode("@fin").Value);

			

			return horaire;

		}

		public virtual XmlElement toXml(XmlDocument document)
		{
			// Start of user code for toXml
			// End of user code for toXml
		}


	}

}
